﻿using System;
using System.Collections.Generic;
using System.Text;

namespace X3DLib
{
    public class Material:X3DObject
    {
        private string DiffuseColor;
        private string AmissiveColor;
        private string SpecularColor;
        private string Shininess;
        private string AmbientIntensity;
        private string Transparency;

        public string diffuseColor
        {
            get { return DiffuseColor; }
            set { DiffuseColor = value; }
        }

        public string emissiveColor
        {
            get { return AmissiveColor; }
            set { AmissiveColor = value; }
        }

        public string specularColor
        {
            get { return SpecularColor; }
            set { SpecularColor = value; }
        }

        public string shininess
        {
            get { return Shininess; }
            set { Shininess = value; }
        }

        public string ambientIntensity
        {
            get { return AmbientIntensity; }
            set { AmbientIntensity = value; }
        }

        public string transparency
        {
            get { return Transparency; }
            set { Transparency = value; }
        }
            
        public Material():base()
        {            
        }

        public Material(string DiffuseColor)
             :base()
        {
            this.DiffuseColor = DiffuseColor;
        }

        public Material(string DEF, string USE, string DiffuseColor, string emissiveColor,
            string specularColor, string shininess, string ambientIntensity, string transparency, string containerField)//: base()
        {
            this.DEF = DEF;
            this.USE = USE;
            this.DiffuseColor = DiffuseColor;
            this.AmissiveColor = emissiveColor;
            this.SpecularColor = specularColor;
            this.Shininess = shininess;
            this.AmbientIntensity = ambientIntensity;
            this.Transparency = transparency;
            this.containerField = containerField;
        }

        public override string getAttrs()
        {
            return "DEF|" + this.DEF + "|string,"
                   + "USE|" + this.USE + "|string,"
                   + "diffuseColor|" + (this.diffuseColor == null ? "0.8 0.8 0.8" : this.diffuseColor) + "|max:1 min:0,"
                   + "emissiveColor" + (this.emissiveColor == null ? "0.0 0.0 0.0" : this.emissiveColor) + "|max:1 min:0,"
                   + "specularColor" + (this.specularColor == null ? "0.0 0.0 0.0" : this.specularColor) + "|max:1 min:0,"
                   + "shininess" + this.shininess == null ? "0.2" : this.shininess + "|float,"
                   + "ambientIntensity" + this.ambientIntensity == null ? "0.2" : this.ambientIntensity + "|float,"
                   + "transparency" + this.transparency == null ? "0.0" : this.transparency + "|float";
        }

        public override void setAttrs(string attrs)
        {
            string[][] temp = X3DString.getArrayByAttrs(attrs);
            for (int i = 0; i < temp.Length; i++)
            {
                switch (temp[i][0])
                {
                    case "DEF":
                        this.DEF = temp[i][1];
                        break;
                    case "USE":
                        this.USE = temp[i][1];
                        break;
                    case "diffuseColor":
                        this.diffuseColor = temp[i][1];
                        break;
                    case "emissiveColor":
                        this.emissiveColor = temp[i][1];
                        break;
                    case "specularColor":
                        this.specularColor = temp[i][1];
                        break;
                    case "shininess":
                        this.shininess = temp[i][1];
                        break;
                    case "ambientIntensity":
                        this.ambientIntensity = temp[i][1];
                        break;
                    case "transparency":
                        this.transparency = temp[i][1];
                        break;
                }
            }
        }
     }
}
